<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
  <script>
    var g =  function* () {
  try {
  console.log("第1次运行")
  yield 1;
  console.log("第2次运行")
  yield 2;
  console.log("第3次运行")
  } catch(error) {
    console.error('出现了错误：', error);
  }
}
const gen = g();
console.log(gen.next())
console.log(gen.next())

console.log(gen.next())
console.log(gen.throw(4))
  </script>
</body>
</html>